import { Body, Controller, Get, Param, Post } from 'routing-controllers';
import { ResumeService } from '../service/resume.service';
import { ResumeEntity } from '../utils/repository';
import { Code } from '../utils/code';
import { Result } from '../utils/result';

import { Service, Inject } from 'typedi';

@Service()
@Controller('/resume')
export class ResumeController {
  @Inject()
  resumeService: ResumeService;

  @Post('/save')
  async save(@Body() entity: ResumeEntity) {
    const index = await this.resumeService.save(entity);
    if (index == 1) {
      return Result.ok(Code.SUCCESS, '保存成功');
    }
    return Result.fail(Code.ERROR_RESUME_ADD, '保存失败');
  }

  @Get('/list/:uid')
  async select(@Param('uid') uid: string) {
    const result = await this.resumeService.select(uid);
    if (result) {
      return Result.ok(Code.SUCCESS, '获取成功', result);
    }
    return Result.fail(Code.ERROR_RESUME_SELECT, '获取失败');
  }
}
